import 'server-only';

import { checkAddressExist } from '@/service/query/address';
import { Button } from '../ui/button';
import {
  Dialog,
  DialogContent,
  DialogDescription,
  DialogHeader,
  DialogTitle,
} from '../ui/dialog';
import CreateEditAddress from './create-edit-address';

export default async function NoAddress({
  children,
}: {
  children: React.ReactNode;
}) {
  const { result, error } = await checkAddressExist();

  if (error || result) return children;

  return (
    <Dialog open={true}>
      <DialogContent>
        <DialogHeader className="space-y-4">
          <DialogTitle>添加地址</DialogTitle>
          <DialogDescription>请添加一个收货地址</DialogDescription>
        </DialogHeader>
        <div className="flex justify-end">
          <CreateEditAddress type="new" button={<Button>添加</Button>} />
        </div>
      </DialogContent>
    </Dialog>
  );
}
